<!--
  A small piece of code to programatically reset a Tomcat connector using JMX.

  Written by Kees Jan Koster and published on Java-monitor.com/forum
-->
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
</head>
<jsp:directive.page import="java.util.*" />
<jsp:directive.page import="javax.management.*" />
<%HttpSession sesja = request.getSession(true);
if(sesja.getAttribute("log")!=null && sesja.getAttribute("log").equals("admin")){

  final ObjectName objectNameQuery = new ObjectName("*:type=Connector,port=8080,*");
	out.println("<br>Trwa resetowanie serwera, proszę czekać . . . ");
  MBeanServer mbeanServer = null;
  ObjectName objectName = null;
  for (final MBeanServer server : (List<MBeanServer>) MBeanServerFactory.findMBeanServer(null)) {
      if (server.queryNames(objectNameQuery, null).size() > 0) {
          mbeanServer = server;
          objectName = (ObjectName) server.queryNames(objectNameQuery, null).toArray()[0];
          
          // we found it, bail out
          break;
      }
  }
  mbeanServer.invoke(objectName, "stop", null, null);
 // Thread.sleep(20000);
  mbeanServer.invoke(objectName, "start", null, null);
  out.println("<br>Serwer został pomyślnie zrestartowany.");
  out.println("<br>Zostaniesz przekierowany na strone główną.");
  %>
  
  <jsp:forward page="index?add=admin"> 
<%}else{
	out.println("<Br>Nie masz uprawnień do wykonania tej operacji!");	
}%>
